

package org.ing.sisval.da;

import java.sql.Connection;
import java.util.ArrayList;
import org.ing.sisval.be.BEUbigeo;
import org.rx.cr.dao.DAOAbstract;


public class DAUbigeo extends DAOAbstract<BEUbigeo> {

    public DAUbigeo(Connection conn) {
    setConnection(conn);
    }
    
    @Override
    public int registrar(BEUbigeo tipo) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int actualizarRegistro(BEUbigeo tipo) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int eliminarRegistro(BEUbigeo tipo) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<BEUbigeo> buscarReferencia(String string) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<BEUbigeo> listar() throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public BEUbigeo buscar(int id) throws Exception {
         try { 
            BEUbigeo bean = null;
            clear();
            setStoreProcedure("sisval.sp_sel_ubigeo_id"); 
            setParameterInt(id);
            commitc();
            while (existResult()) {
                bean = new BEUbigeo(); 
                bean.setUbigeoid(getDataInt(1));
                bean.setDepartamento(getDataString(2));
                bean.setProvincia(getDataString(3));
                bean.setDistrito(getDataString(4));
                
            }   
            close();
            return bean;            
        } catch (Exception ex) {
            rollback(ex);
            return null;            
        }finally{
        }
    }
    
    public ArrayList<BEUbigeo> listarDepartamento() throws Exception {      
      try {             
            clear();
            setStoreProcedure("sisval.sp_listar_departamento");
            commitc();
            while (existResult()){ 
              BEUbigeo bean = new BEUbigeo();             
              
              bean.setDepartamento(getDataString(1));
              add(bean);
            }
            close();
            return getLista();
        } catch (Exception ex) {
            rollback(ex);
            return null;
        }finally{
        }       
    }    
    public ArrayList<BEUbigeo> listarProvinciaDepartamento(String depa) throws Exception{      
      try {             
            clear();
            setStoreProcedure("sisval.sp_listar_provincia");            
            setParameterString(depa);
            commitc();
            while (existResult()){ 
              BEUbigeo bean = new BEUbigeo();
             
              bean.setProvincia(getDataString(1));
              add(bean);
            }  
            close();
           return getLista();
        } catch (Exception ex) {
           rollback(ex);
           return null;
        }finally{
        }       
    }    
    public ArrayList<BEUbigeo> listarDistritoProvinciaDepartamento(String depa, String pro) throws Exception{      
      try {             
            clear();
            setStoreProcedure("sisval.sp_listar_distrito");            
            setParameterString(depa);
            setParameterString(pro);
            commitc();
            while (existResult()){ 
              BEUbigeo bean = new BEUbigeo();              
              bean.setUbigeoid(getDataInt(1)); 
              bean.setDistrito(getDataString(2));
              add(bean);
            }  
            close();
            return getLista();
        } catch (Exception ex) {
            rollback(ex);           
            return null;
        }finally{
        }       
    }
    
}
